package com.screen.screendisplay.service.impl.dryport;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.screen.screendisplay.entity.dryport.DryportSafetyenvLine;
import com.screen.screendisplay.mapper.dryport.DryportSafetyenvLineMapper;
import com.screen.screendisplay.service.dryport.DryportSafetyenvLineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.screen.screendisplay.vo.dryport.LineVO;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 营业线路计划情况表 服务实现类
 * </p>
 *
 * @author xuesong
 * @since 2025-08-23
 */
@Service
public class DryportSafetyenvLineServiceImpl extends ServiceImpl<DryportSafetyenvLineMapper, DryportSafetyenvLine> implements DryportSafetyenvLineService {

    @Override
    public List<LineVO> getLineStatistics(Integer year) {
        // 设置默认年份为2025
        if (year == null) {
            year = 2025;
        }
        
        // 查询指定年份的数据
        LambdaQueryWrapper<DryportSafetyenvLine> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DryportSafetyenvLine::getYear, year);
        queryWrapper.orderByAsc(DryportSafetyenvLine::getDate);
        List<DryportSafetyenvLine> entityList = this.list(queryWrapper);
        
        // 转换为VO对象列表
        List<LineVO> result = new ArrayList<>();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        
        for (DryportSafetyenvLine entity : entityList) {
            LineVO vo = new LineVO();
            
            // 格式化日期为字符串
            if (entity.getDate() != null) {
                vo.setDate(dateFormat.format(entity.getDate()));
            }
            
            vo.setRailwayLine(entity.getRailwayLine());
            vo.setNonRailwayLine(entity.getNonRailwayLine());
            vo.setRailwayPlanned(entity.getRailwayPlanned());
            vo.setRailwayCompleted(entity.getRailwayCompleted());
            vo.setNonRailwayPlanned(entity.getNonRailwayPlanned());
            vo.setNonRailwayCompleted(entity.getNonRailwayCompleted());
            
            result.add(vo);
        }
        
        return result;
    }

}
